package com.guoguo.base;

import com.alibaba.fastjson.JSONObject;

import javax.servlet.Filter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by Administrator on 2017/8/18 0018.
 */
public abstract class BaseFilter implements Filter {
    /**
     * 返回消息
     *
     * @param jsonObject
     * @param response
     * @throws IOException
     * @throws ServletException
     */
    public void requestFailedSolution(int appId,JSONObject jsonObject, HttpServletResponse response) throws IOException, ServletException {
        if (appId == 0) {
            response.sendRedirect("/index.html");
        } else {
            response.setHeader("Content-type", "text/html;charset=UTF-8");
            response.setCharacterEncoding("UTF-8");
            PrintWriter out = response.getWriter();
            out.write(jsonObject.toJSONString());
            out.flush();
            out.close();
        }
    }
}
